/**
 * @description: instanceof
 * @author: huen2015
 */

import { IFn } from './types'

function instanceOf(obj: object, Fn: IFn): boolean {
	if (typeof obj !== 'object') return false

	let result = false
	let proto = Reflect.getPrototypeOf(obj)

	while (proto) {
		if (proto.constructor === Fn) {
			result = true
			break
		} else {
			proto = Reflect.getPrototypeOf(proto)
		}
	}

	return result
}

console.log('instanceOf([], Array)', instanceOf([], Array))
console.log('instanceOf([], Object)', instanceOf([], Object))
console.log('instanceOf([], Date)', instanceOf([], Date))

export { instanceOf }
